import { ConfigEnv, loadEnv } from 'vite'
import  alias from './vite/alias'
import setupPlugins from './vite/plugins/index'
import { parseEvn } from './vite/util'
import { visualizer } from "rollup-plugin-visualizer";

// https://vitejs.dev/config/
export default ({command,mode}:ConfigEnv)=>{
  const isBuild  =command=='serve'
  const root=process.cwd()
  const env=parseEvn(loadEnv(mode,root))
 return{
  plugins: [...setupPlugins(false),visualizer()],
  resolve:{
    alias:alias 
  },

  build: {
    rollupOptions: {
      emptyOutDir: true,
      output: {
        manualChunks(id: string) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
        },
      },
    },
  },

// //开发环境设置
//   server: {
   
//     // host:'39.107.104.186',
// 		// port:4000,    //设置服务启动端口
// 		open:true,    //设置服务启动时是否自动打开浏览器
// 		cors:true,    //允许跨域
//     proxy: {
//       '/api': {
//         target: "http://39.107.104.186:8880/",
//         //跨域请求携带cookie
//         changeOrigin: true,
//         rewrite: (path: string) => path.replace(/^\/api/, ''),
//       },
//     },
//   },
} 
} 
  

